<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	/**
	 * Set the route for api
	 */
	protected function _initRestRoute()
	{
		$frontController = Zend_Controller_Front::getInstance();
		$restRoute = new Zend_Rest_Route($frontController, array(), array('api'));
		$frontController->getRouter()->addRoute('rest', $restRoute);
	}

	public function _initRoutes()
	{
		$frontController = Zend_Controller_Front::getInstance();
		$router = $frontController->getRouter();
		 
		$loginRoute = new Zend_Controller_Router_Route(
                    '/api/user/login',
		array(
                        'module' => 'api',
                        'controller' => 'user',
                        'action' => 'login'
                        )
                        );

                        $changepassRoute = new Zend_Controller_Router_Route(
                    '/api/user/changepass',
                        array(
                        'module' => 'api',
                        'controller' => 'user',
                        'action' => 'changepass'
                        )
                        );

                        $r1 = new Zend_Controller_Router_Route_Regex('api/photo/(.*)/comment',
                        array('module' => 'api' ,'controller' => 'comment', 'action' => 'index'),
                        array(1 => 'param1')
                        );

                        $r2 = new Zend_Controller_Router_Route_Regex('api/location/(.*)/tour/(.*)',
                        array('module' => 'api' ,'controller' => 'tour', 'action' => 'get'),
                        array(1 => 'param1', 2=>'param2')
                        );

                        $r4 = new Zend_Controller_Router_Route_Regex('api/(.*)/(.*)/photo',
                        array('module' => 'api' ,'controller' => 'photo', 'action' => 'index'),
                        array(1 => 'resource', 2 => 'id')
                        );

                        $r5 = new Zend_Controller_Router_Route_Regex('api/(.*)/(.*)/tour',
                        array('module' => 'api' ,'controller' => 'tour', 'action' => 'index'),
                        array(1 => 'param1', 2 => 'param2')
                        );
                        $r6 = new Zend_Controller_Router_Route_Regex('api/user/(.*)/message',
                        array('module' => 'api' ,'controller' => 'message', 'action' => 'index'),
                        array(1 => 'param1')
                        );

                        $r10 = new Zend_Controller_Router_Route_Regex('api/user/(.*)/to_user/(.*)/message',
                        array('module' => 'api' ,'controller' => 'message', 'action' => 'getusermessage'),
                        array(1 => 'param1', 2 => 'param2')
                        );

                        $r7 = new Zend_Controller_Router_Route_Regex('api/user/(.*)/friend',
                        array('module' => 'api' ,'controller' => 'friend', 'action' => 'index'),
                        array(1 => 'param1')
                        );

                        $r8 = new Zend_Controller_Router_Route_Regex('api/friend/(.*)',
                        array('module' => 'api' ,'controller' => 'friend', 'action' => 'post'),
                        array(1 => 'param1')
                        );
                        $r9 = new Zend_Controller_Router_Route_Regex('api/user/(.*)/friend/(.*)',
                        array('module' => 'api' ,'controller' => 'friend', 'action' => 'put'),
                        array(1 => 'param1', 2 => 'param2')
                        );

                        $r11 = new Zend_Controller_Router_Route_Regex('api/user/(.*)/search',
                        array('module' => 'api' ,'controller' => 'user', 'action' => 'searchuser'),
                        array(1 => 'param1')
                        );

                        $r12 = new Zend_Controller_Router_Route_Regex('api/tour/(.*)/member',
                        array('module' => 'api' ,'controller' => 'tour', 'action' => 'getmember'),
                        array(1 => 'param1')
                        );

                        $r13 = new Zend_Controller_Router_Route_Regex('api/user/(.*)/other_user/(.*)',
                        array('module' => 'api' ,'controller' => 'user', 'action' => 'otheruser'),
                        array(1 => 'param1', 2 => 'param2')
                        );

                        $r14 = new Zend_Controller_Router_Route_Regex('api/user/(.*)/notification',
                        array('module' => 'api' ,'controller' => 'notification', 'action' => 'index'),
                        array(1 => 'param1')
                        );

                        $r15 = new Zend_Controller_Router_Route_Regex('api/tour/(.*)/invite',
                        array('module' => 'api' ,'controller' => 'tour', 'action' => 'invite'),
                        array(1 => 'param1')
                        );

                        $r17 = new Zend_Controller_Router_Route_Regex('api/user/(.*)/unlike',
                        array('module' => 'api' ,'controller' => 'like', 'action' => 'put'),
                        array(1 => 'param1')
                        );

                        $r18 = new Zend_Controller_Router_Route_Regex('api/tour/(.*)/check',
                        array('module' => 'api' ,'controller' => 'tour', 'action' => 'check'),
                        array(1 => 'param1')
                        );

                        $r19 = new Zend_Controller_Router_Route_Regex('api/tour/(.*)/join',
                        array('module' => 'api' ,'controller' => 'tour', 'action' => 'join'),
                        array(1 => 'param1')
                        );

                        $r20 = new Zend_Controller_Router_Route_Regex('api/tour/(.*)/answer',
                        array('module' => 'api' ,'controller' => 'tour', 'action' => 'answer'),
                        array(1 => 'param1')
                        );

                        $r21 = new Zend_Controller_Router_Route_Regex('api/tour/(.*)/chat',
                        array('module' => 'api' ,'controller' => 'tourchat', 'action' => 'index'),
                        array(1 => 'param1')
                        );

                        $r22 = new Zend_Controller_Router_Route_Regex('api/tour/(.*)/checkinlocation',
                        array('module' => 'api' ,'controller' => 'tour', 'action' => 'getcheckin'),
                        array(1 => 'param1')
                        );

                        $r23 = new Zend_Controller_Router_Route_Regex('api/user/(.*)/location/(.*)',
                        array('module' => 'api' ,'controller' => 'location', 'action' => 'get'),
                        array(1 => 'param1', 2=>'param2')
                        );

                        $r24 = new Zend_Controller_Router_Route_Regex('api/user/(.*)/photo/(.*)',
                        array('module' => 'api' ,'controller' => 'photo', 'action' => 'get'),
                        array(1 => 'param1', 2=>'param2')
                        );

                        $r25 = new Zend_Controller_Router_Route_Regex('api/location/search',
                        array('module' => 'api' ,'controller' => 'location', 'action' => 'searchlocation')
                        );

                        $r26 = new Zend_Controller_Router_Route_Regex('api/latitude/(.*)/longitude/(.*)',
                        array('module' => 'api' ,'controller' => 'location', 'action' => 'getnear'),
                        array(1 => 'param1', 2=>'param2')
                        );

                        $r27 = new Zend_Controller_Router_Route_Regex('api/checkinlocation/user/(.*)',
                        array('module' => 'api' ,'controller' => 'user', 'action' => 'getcheckin'),
                        array(1 => 'param1')
                        );
                        
                        $r28 = new Zend_Controller_Router_Route_Regex('api/tour/(.*)/out',
                        array('module' => 'api' ,'controller' => 'tour', 'action' => 'out'),
                        array(1 => 'param1')
                        );
                        
                        $r29 = new Zend_Controller_Router_Route_Regex('api/checkin',
                        array('module' => 'api' ,'controller' => 'tour', 'action' => 'checkin'),
                        array(1 => 'param1')
                        );


                        //
                        //

                        $routesArray = array(
            'login' => $loginRoute,
            'changepass' => $changepassRoute,
            'route1' => $r1,
            'route2' => $r2,
            'route4' => $r4,
            'route5' => $r5,
            'route6' => $r6,
            'route7' => $r7,
            'route8' => $r8,
            'route9' => $r9,
            'route10' => $r10,
            'route11' => $r11,
            'route12' => $r12,
            'route13' => $r13,
            'route14' => $r14,
            'route15' => $r15,
                        //'route16' => $r16,
            'route17' => $r17,
            'route18' => $r18,
            'route19' => $r19,
            'route20' => $r20,
            'route21' => $r21,
            'route22' => $r22,
            'route23' => $r23,
            'route24' => $r24,
            'route25' => $r25,
            'route26' => $r26,
            'route27' => $r27,
            'route28' => $r28,
            'route29' => $r29                
                        );


                        $router->addRoutes('route6', $r);


                        $router->addRoutes($routesArray);
	}

	public function _initSession(){
		Zend_Session::start();
	}


//	protected function _initDB(){
//		$db = Zend_Db::factory('PDO_MYSQL', array ('host' => 'localhost', 'username' => 'root',
//                                                                            'password' => '111111',  
//                                                                            'dbname' => 'your_tour')); 
//		$db->setFetchMode(Zend_Db::FETCH_BOTH);
//		Zend_Db_Table::setDefaultAdapter($db);
//		Zend_Registry::set('DB',$db);
//		return $db;
//	}

        protected function _initDB(){
	
  
	
	$dbOption = $this->getOption('resources');
    	$dbOption = $dbOption['db'];
    	
    	// Setup database
    	$db = Zend_Db::factory($dbOption['adapter'], $dbOption['params']);
    	$db->setFetchMode(Zend_Db::FETCH_ASSOC);
    	$db->query("SET NAMES 'utf8'");
    	$db->query("SET CHARACTER SET 'utf8'");
    	
    	Zend_Registry::set('DB', $db);
    	
    	//Khi thiet lap che do nay model moi co the su dung duoc
    	Zend_Db_Table::setDefaultAdapter($db);
    	
    	// Return it, so that it can be stored by the bootstrap
    	return $db;
        }

}

